import { request } from "@/http/axios"
import {timeFormats} from "../projectType/projectTypeApi.js"
import * as XLSX from "xlsx";
export function projectAll() {
  return request({
    url: '/projectType/all',
    method: "get"
  })
}

export function getTeacherType() {
  return request({
    url: '/project/teacherType',
    method: "get"
  })
}


export function projectAlls() {
  return request({
    url: '/project/all',
    method: "get"
  })
}

export function selectProjectTitle(title) {
  const url = `project/title?title=${encodeURIComponent(title)}`;
  return request({
    url: url,
    method: 'get',
  })
}

export function projectAdds(form) {
  return request({
    url: 'project/projectAdd',
    method: 'post',
    data: form
  })
}
export function projectBatchAdds(form) {
  return request({
    url: 'project/projectBatchAdd',
    method: 'post',
    data: form,
  })
}

export function projectEdits(form) {
  return request({
    url: 'project/projectEdit',
    method: 'post',
    data: {
      id: form.id,
      title: form.title,
      content: form.content,
      isSubmit: form.isSubmit,
      type: form.type,
      username: form.username,
      menber: form.menber,
      status: form.status,
      file: form.file,
      fileList: form.fileList,
      projectImg: form.projectImg,
      download: form.download
    }
  })
}
// 根据id获取项目信息
export function projectInfoById(id) {
  return request({
    url: 'project/selectById?id='+id,
    method: 'get',
  })
}
// 根据idd获取项目信息
export function projectInfoByIds(ids) {
  return request({
    url: 'project/selectByIds?ids='+ids,
    method: 'get',
  })
}
export function projectPage(form, pageSize, pageNum) {
  return request({
    url: 'project/projectPage',
    method: 'post',
    data: {
      pageSize: pageSize,
      pageNum: pageNum,
      title: form.title,
      isSubmit: form.isSubmit,
      type: form.type,
      status: form.status,
      username: form.username,
      teacherId: form.teacherId,
      userId: form.userId,
    }
  })
}

export function projectDelects(Ids) {
  return request({
    url: 'project/projectDelects',
    method: 'post',
    data: {
      Ids: Ids
    }
  })
}

export function projectStatistics(userType, begin, end) {
  return request({
    url: 'project/projectStatistics',
    method: 'post',
    data: {
      type: userType,
      begin: begin,
      end: end
    }
  })
}

export function prjectExport(begin, end,ExcelType) {
  return request({
    url: 'project/export',
    method: 'post',
    data: {
      begin: begin,
      end: end,
      excelType: ExcelType
    }
  })
}


export function removeFile(fileName) {
  const url = `upload/delFile?fileName=${encodeURIComponent(fileName)}`;
  return request({
    url: url,
    method: 'get',
  });
}
export function getFile(fileName) {
  const url = `upload/getFiles?fileName=${encodeURIComponent(fileName)}`;
  return request({
    url: url,
    method: 'get',
  });
}
export function ExportProjectExcel(data){
  let tableData = [
    ['序号', '项目名称', '项目介绍', '项目类型', '项目发起人', '发起时间', '项目成员', '项目状态', '项目附件', '项目图片', '是否支持下载']//导出表头
  ] // 表格表头
  data.forEach((item, index) => {
    let rowData = []
    //导出内容的字段
    rowData = [
      index + 1,
      item.title,
      item.content,
      item.protype,
      item.username,
      item.createTime,
      item.menber,
      item.statuss,
      item.file,
      item.projectImg,
      item.download===0?'是':'否',
    ]
    tableData.push(rowData)
  })
  let workSheet = XLSX.utils.aoa_to_sheet(tableData);
  let bookNew = XLSX.utils.book_new();
  XLSX.utils.book_append_sheet(bookNew, workSheet, '作品名称') // 工作簿名称
  let name = '项目数据' + timeFormats() + '.xlsx'
  XLSX.writeFile(bookNew, name) // 保存的文件名
}


























